Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve logging and exiting #309

Merged
merged 3 commits into from
Jun 29, 2024

Conversation

tmuehlbacher
Copy link

Gives more control over the logging by also allowing log level control through environment variable e.g. BCACHEFS_LOG=trace. This is useful in some contexts where it's more difficult to change the CLI argument than it is to change the environment. Also useful for CI to centrally set the logging to be verbose.

Beyond that, also stop using std::process:exit() in favor of ExitCode for better error printing.

Instead of the custom logger impl, which limits the features we can
easily provide for users.

This introduces the `BCACHEFS_LOG` environment variable for setting the
log verbosity. Setting `BCACHEFS_LOG=trace`, e.g. in a test environment,
will yield all log messages.

Also I think it's reasonable to print INFO level logs by default.

Signed-off-by: Thomas Mühlbacher <[email protected]>
To silence log outputs on the CLI.

Signed-off-by: Thomas Mühlbacher <[email protected]>
Should provide us with better outputs on process failure, also makes
unwinding better and is generally recommended over `exit()`.

Signed-off-by: Thomas Mühlbacher <[email protected]>
@tmuehlbacher
Copy link
Author

env_logger is maintained by the rust-lang-nursery team and pretty widely used.

$ tokei env_logger-0.10.2 is-terminal-0.4.12 termcolor-1.4.1
===============================================================================
 Language            Files        Lines         Code     Comments       Blanks
===============================================================================
 TOML                    4          249          189           30           30
-------------------------------------------------------------------------------
 Markdown                3          284            0          195           89
 |- BASH                 2           41           37            0            4
 |- Rust                 3           73           58            1           14
 |- TOML                 1            5            4            0            1
 (Total)                            403           99          196          108
-------------------------------------------------------------------------------
 Rust                   27         5872         4854          353          665
 |- Markdown             9         1528           11         1112          405
 (Total)                           7400         4865         1465         1070
===============================================================================
 Total                  34         6405         5043          578          784
===============================================================================
$ cargo bloat --crates -n 100
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.06s
    Analyzing target/debug/bcachefs

 File  .text     Size Crate
 3.7%  31.4%   1.1MiB [Unknown]
 3.6%  30.2%   1.1MiB clap_builder
 1.9%  16.1% 584.0KiB std
 0.7%   5.9% 215.4KiB clap_complete
 0.3%   2.8% 100.3KiB env_logger
 0.3%   2.3%  82.4KiB bcachefs
 0.2%   1.5%  53.1KiB anyhow
 0.1%   1.1%  39.0KiB bch_bindgen
 0.1%   0.9%  33.4KiB strsim
 0.1%   0.9%  33.1KiB termcolor
 0.1%   0.7%  26.2KiB clap_lex
 0.1%   0.6%  22.7KiB uuid
 0.1%   0.5%  19.5KiB rtoolbox
 0.1%   0.5%  19.1KiB anstream
 0.0%   0.3%  12.3KiB rpassword
 0.0%   0.3%  12.3KiB rustix
 0.0%   0.2%   8.9KiB log
 0.0%   0.2%   8.2KiB anstyle
 0.0%   0.2%   7.9KiB udev
 0.0%   0.1%   5.4KiB bitflags
 0.0%   0.1%   4.6KiB zeroize
 0.0%   0.1%   3.6KiB errno
 0.0%   0.0%   1.5KiB terminal_size
 0.0%   0.0%   1.1KiB utf8parse
 0.0%   0.0%   1.0KiB colorchoice
 0.0%   0.0%     575B byteorder
 0.0%   0.0%     541B anstyle_parse
 0.0%   0.0%     435B memchr
 0.0%   0.0%      18B anstyle_query
11.8% 100.0%   3.6MiB .text section size, the file size is 30.1MiB

Note: numbers above are a result of guesswork. They are not 100% correct and never will be.

@koverstreet koverstreet merged commit d061c7e into koverstreet:master Jun 29, 2024
1 check passed
@tmuehlbacher tmuehlbacher deleted the improve-logging-exiting branch June 29, 2024 18:24
@tmuehlbacher
Copy link
Author

Release build numbers, probably more useful to consider:

$ cargo bloat --release --crates -n 100
    Finished `release` profile [optimized] target(s) in 0.06s
    Analyzing target/release/bcachefs

 File  .text     Size Crate
 8.2%  52.1%   1.1MiB [Unknown]
 2.7%  17.4% 380.5KiB std
 2.6%  16.7% 365.8KiB clap_builder
 0.8%   5.2% 113.5KiB clap_complete
 0.7%   4.2%  91.6KiB bcachefs
 0.2%   1.1%  25.1KiB env_logger
 0.1%   0.4%   9.7KiB anyhow
 0.0%   0.3%   5.6KiB bch_bindgen
 0.0%   0.2%   4.4KiB uuid
 0.0%   0.1%   2.9KiB clap_lex
 0.0%   0.1%   2.8KiB rpassword
 0.0%   0.1%   2.5KiB anstyle
 0.0%   0.1%   2.0KiB strsim
 0.0%   0.1%   1.6KiB anstream
 0.0%   0.1%   1.6KiB udev
 0.0%   0.1%   1.1KiB log
 0.0%   0.0%     942B zeroize
 0.0%   0.0%     826B errno
 0.0%   0.0%     749B termcolor
 0.0%   0.0%     688B rtoolbox
 0.0%   0.0%     435B memchr
 0.0%   0.0%     227B terminal_size
 0.0%   0.0%       8B colorchoice
15.7% 100.0%   2.1MiB .text section size, the file size is 13.7MiB

Note: numbers above are a result of guesswork. They are not 100% correct and never will be.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants